package com.apes.fn.tms.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 运单货物明细
 * @author yiny
 * 2020.3.9
 */
@Getter
@Setter
@DynamicInsert
@DynamicUpdate
@SelectBeforeUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WaybillCargoDetails.CONST_TABLE_NAME,uniqueConstraints = {@UniqueConstraint(columnNames = {"waybill_id","product_id"})})
public class WaybillCargoDetails extends BaseModel {
    public static final String CONST_TABLE_NAME = "TMS_WAYBILL_CARGO_DETAILS";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "运单货物明细")
    @Comment("运单货物明细")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "waybill_id", referencedColumnName = "id")
    @Comment("运单号")
    private Waybill waybillId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品编码")
    private Product productId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom productUomId;

    @Column(name = "number_qty")
    @Comment("数量")
    private double numberQty;

    @Column(name = "loading_qty")
    @Comment("装货数量")
    private double loadingQty;//确切装运的数量

    @Column(name = "price_unit", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("单价")
    private double priceUnit = 0;

    @Column(name = "loading_price_unit",columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("揽件单价")
    private double loadingPriceUnit;//揽件单价

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "source_state", referencedColumnName = "id" )
    @Comment("货源状态")
    private Enumeration sourceState;
}
